#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
//6377:生日相同 2.0
struct Student{
    int day,month,len;
    string name;
};
Student stu[185];
struct Rule1{
    bool operator()(const Student &a1,const Student &a2){
        return a1.month<a2.month;
    }
};
struct Rule2{
    bool operator()(const Student &a1,const Student &a2){
        return a1.day<a2.day;
    }
};
struct Rule3{
    bool operator()(const Student &a1,const Student &a2){
        return a1.len<a2.len;
    }
};
struct Rule4{
    bool operator()(const Student &a1,const Student &a2){
        return strcmp(a1.name.c_str(),a2.name.c_str())<0;
    }
};
bool myless(Student x,Student y){
    if(x.month!=y.month)return x.month<y.month;
    else if(x.month==y.month&&x.day!=y.day)return x.day<y.day;
    else if(x.month==y.month&&x.day==y.day&&x.len!=y.len)return x.len<y.len;
    else return x.name<y.name;
}
int main(){
    //6377:生日相同 2.0

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>stu[i].name>>stu[i].month>>stu[i].day;
        stu[i].len=stu[i].name.size();
    }
    // //按名字的字典序排序
    // sort(stu,stu+n,Rule4());
    // //按名字的长度排序
    // sort(stu,stu+n,Rule3());
    // //按生日的天排序
    // sort(stu,stu+n,Rule2());
    // //按生日的月排序
    // sort(stu,stu+n,Rule1());
    sort(stu,stu+n,myless);
    bool flag=false;
    for(int i=0;i<n;){
        if(stu[i].month==stu[i+1].month&&stu[i].day==stu[i+1].day){
            flag=true;
            cout<<stu[i].month<<" "<<stu[i].day<<" "<<stu[i].name<<" ";
            i++;
            while(stu[i].month==stu[i-1].month&&stu[i].day==stu[i-1].day){
                cout<<stu[i].name<<" ";
                i++;
            }
            cout<<endl;
        }else{
            i++;
        }
    }
    if(flag==false){
        cout<<"None"<<endl;
    }
    return 0;
}